package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.pojo.DefectRecord;
import com.zhentao.pojo.InspectionTask;
import com.zhentao.service.DefectRecordService;
import com.zhentao.service.InspectionTaskService;
import com.zhentao.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/inspection")
public class InspectionController {

    @Autowired
    private InspectionTaskService taskService;

    @Autowired
    private DefectRecordService defectService;

    // 检测任务管理
    @RequestMapping("/task/list")
    public Result getTaskList(@RequestBody com.zhentao.pojo.Page page) {
        Page<InspectionTask> page1 = new Page<>(page.getPageNum(), page.getPageSize());
        QueryWrapper<InspectionTask> queryWrapper=new QueryWrapper<>();
        Page<InspectionTask> list=taskService.page(page1,queryWrapper);
        return Result.OK(list);
    }

    @RequestMapping("/task/detail/{id}")
    public Result getTaskDetail(@PathVariable Long id) {
        InspectionTask task = taskService.getById(id);
        return Result.OK(task);
    }

    @RequestMapping("/task/status")
    public Result updateTaskStatus(@RequestBody InspectionTask task) {
        taskService.updateById(task);
        return Result.OK();
    }

    // 缺陷记录管理
    @RequestMapping("/defect/list")
    public Result getDefectList(@RequestBody com.zhentao.pojo.Page page) {
        Page<DefectRecord> page1 = new Page<>(page.getPageNum(), page.getPageSize());
        QueryWrapper<DefectRecord> queryWrapper=new QueryWrapper<>();
        Page<DefectRecord> list = defectService.page(page1,queryWrapper);
        return Result.OK(list);
    }

    @RequestMapping("/defect/add")
    public Result addDefect(@RequestBody DefectRecord defect) {
        defectService.save(defect);
        return Result.OK();
    }

    @RequestMapping("/defect/update")
    public Result updateDefect(@RequestBody DefectRecord defect) {
        defectService.updateById(defect);
        return Result.OK();
    }

    @RequestMapping("/defect/delete/{id}")
    public Result deleteDefect(@PathVariable Long id) {
        defectService.removeById(id);
        return Result.OK();
    }
}
